rm(list=ls())

library(tidyverse)

data <- read_csv('NYT_UN_Hits.csv')

data %>% filter(Term != '\bUN\b') %>% 
  mutate(Month = factor(month.abb[Month], levels=month.abb)) %>%
  group_by(Month, Term) %>%
  dplyr::summarise(mean = mean(Hits),
                   sd = sd(Hits),
                   upper = mean + 1.96*sd/(n() - 1),
                   lower = mean - 1.96*sd/(n() - 1)) %>%
  ggplot(aes(x=Month, y=mean, ymin = lower, ymax = upper, color=Term)) + 
  geom_errorbar(width = 0.1) + geom_line() + xlab(NULL) + ylab('NYT Hits') + 
  theme(legend.position = 'none',
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +
  scale_color_manual(values = c('United Nations' = 'blue', 'General Assembly' = 'red')) + 
  annotate('text', x='Nov', y=45, label='United Nations', color='blue') +
  annotate('text', x='Nov', y=12.5, label='General Assembly', color='red')

         